package com.example.uniappspringbootstartweb.mapper;

import com.example.uniappspringbootstartweb.entity.User;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;

import java.util.Optional;

/**
 * Created by lilijava
 * on 2024/12/28
 * <p>
 * on  uni-app-springboot-start-web
 */
@Repository
public interface UserRepository extends JpaRepository<User, Long> {
    // 自定义查询方法：根据用户名查找用户

    // 根据用户名查找用户
    Optional<User> findByUsername(String username);

    // 检查用户名是否已存在
    boolean existsByUsername(String username);
    User findAllById(Long id);
    @Query("SELECT u FROM User u WHERE u.username = :username AND u.password = :password")
    Optional<User> findByUsernameAndPassword(@Param("username") String username, @Param("password") String password);
}
